#pragma once

#include <math.h>
#include <stdlib.h>

#include "Vector2D.h"
#include "clkAABB.h"

#define MATH_PI 3.141592654f
#define FLOAT_MAX 3.402823466e+38F
#define FLOAT_MIN 1.175494351e-38F
#define SQ_CTR(x,y) V2DF(x/2,y/2)
#define RADIAN(degree) (degree*(MATH_PI/180.0f))
#define DEGREE(radian) (radian*(180.0f/MATH_PI))
#define MAX_VAL(a,b) (a>b)?a:b
#define MIN_VAL(a,b) (a<b)?a:b

enum PFLAG
{
	PF_DEFAULT,
	PF_DELTA,
};

int randomInt();
int randomInt(int min, int max);
float randomFloat();
float randomFloat(float min, float max);

void clamp(float& value, float min, float max);
void clamp(V2DF& value, float min, float max);

void rotateVec(V2DF& vec, float dgr);
void translateVec(V2DF& vec, V2DF trn);

V2DF centeroid(V2DF* verts);

void genMinMax(V2DF& min, V2DF& max, float width, float height);
void genMinMax(V2DF& min, V2DF& max, V2DF* verts);

clkAABB genAABB(V2DF pos, float width, float height);
clkAABB genAABB(V2DF pos, V2DF* verts);

bool overlapAABB(clkAABB abA, clkAABB abB);
bool pointInAABB(V2DF pnt, V2DF min, V2DF max);

void calcPhysics(V2DF& pos, float& rot, V2DF& lvel, float& avel,
	V2DF lfrc, float afrc, float ldamp, float adamp,
	float mass, float inertia, float time);

struct satProj
{
	float minValue;
	float maxValue;

	satProj();
	satProj(float mn, float mx);
	bool overlap(satProj prj, float* ovr = 0);
};

satProj satProject(V2DF* verts, V2DF axis);
bool satCollision(V2DF* vertsA, V2DF* normsA, V2DF* vertsB,
	V2DF* normsB, V2DF* mtvAxis, float* mtvMag);